package com.desaysv.hicar.base;

import android.content.Context;
import androidx.annotation.LayoutRes;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public  class  BaseRecycleAdapter extends RecyclerView.Adapter {
    private BaseCall mCall;

    public BaseRecycleAdapter() {
    }
    public BaseRecycleAdapter(BaseCall mCall) {
        this.mCall = mCall;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        return new HolderProxy(mCall.setView());
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int i) {
        mCall.bind(viewHolder.itemView,i);
    }

    @Override
    public int getItemCount() {
        return mCall.setSize();
    }

    public class HolderProxy extends RecyclerView.ViewHolder{

        public HolderProxy(@NonNull View itemView) {
            super(itemView);
        }

        public HolderProxy(@LayoutRes int layoutId){
           this(LayoutInflater.from(mCall.setContext()).inflate(layoutId,null,false));
        }
    }


   public interface BaseCall{
        Context setContext();
        @LayoutRes int setView();
        int setSize();
        void bind(View item,int position);
    }
}
